import request from '@/utils/request'

export function getLogs(data) {
    let hostIpList = [];
    if (data.host) {
        hostIpList = data.host;
        delete data.host;
    }
    let hostParams = "";
    hostIpList.forEach(ip => {
        hostParams = hostParams + `&hostIpList=${ip}`
    })
    let url = "";
    for (let key in data) {
        if (data[key]) {
            url = url ? url + `&${key}=${data[key]}` : `?${key}=${data[key]}`
        }
    }
    return request({
        url: '/logs'+ url + hostParams,
        method: 'get'
    })
}

export function getLogSub({id, ...data}) {
    return request({
        url: `/logs/${id}/sub`,
        method: 'get',
        params: data
    })
}

export function getLogDetail({id, ...data}) {
    return request({
        url: `/logs/${id}`,
        method: 'get',
        params: data
    })
}

export function continueTask({id}) {
    return request({
        url: `/logs/${id}/resume/`,
        method: 'put'
    })
}

export function pauseTask({id}) {
    return request({
        url: `/logs/${id}/pause`,
        method: 'put'
    })
}

export function cancelTask({id}) {
    return request({
        url: `/logs/${id}/cancel`,
        method: 'put'
    })
}

export function exportSubLog(data) {
    return request({
        url: '/logs/exportSubLog',
        method: 'post',
        data,
        responseType: 'blob',
    })
}

export function logRollback(data) {
    return request({
        url: '/logs/rollback',
        method: 'put',
        data
    })
}

export function logBackOff(data) {
    return request({
        url: 'logs/cveRollbackFromSublog',
        method: 'put',
        data
    })
}